import model.UserBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

public class App {
    public static void main(String[] args) {
        //1.1获取到Spring的上下文对象
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        //1.2获取到Spring的上下文对象
        //BeanFactory beanFactory = new ClassPathXmlApplicationContext("spring-config.xml");
        //BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));

        //2.1从Spring（上下文）中获取到业务对象，通过bean的id
        //UserBean user = (UserBean) context.getBean("user");
        //2.2从Spring（上下文）中获取到业务对象，通过对象类型
        //UserBean user = context.getBean(UserBean.class);
        //2.3从Spring（上下文）中获取到业务对象，通过id+对象类型
        UserBean user = context.getBean("user",UserBean.class);

        //3.使用业务对象
        user.printName("java");
    }
}
